

<!-- 我的中奖记录 -->
<template>
	<view>
		<view v-if="myPrizeList && myPrizeList.length">
			<view v-for="(item, index) in myPrizeList" class="onePrize">
				<view class="prizeInfo">
					<view class="prizeType">
						{{item.prizeType | prizeTypeFilter}}
					</view>
					<view class="prizeName ellipsis1">
						{{item | prizeNameFilter}}
					</view>
					<view class="dateTime">
						{{item.receiveTime| formatDateTime}}
					</view>
				</view>
				
				<view v-if="item.prizeType == 20 || item.prizeType == 30" class="prizeStatus">
					<view class="status">
						已发放
					</view>
				</view>
				<view v-else class="prizeStatus">
					<view @click="sureOperateHandler(index)" v-if="item.receiveStatus == 20" class="status goods">
						去核销
					</view>
					<view v-else class="status">
						已发放
					</view>
				</view>
			</view>
		</view>
		<g-empty v-else></g-empty>
	</view>
</template>

<script>
	import dateTimeUtil from '@/common/dateTimeUtil.js'
	export default {
		filters: {
			
			//奖品类型
			prizeTypeFilter(prizeType) {
				
				var prizeTypeName = "";
				switch(prizeType) {
					case 10:
						prizeTypeName = "商品";
						break;
					case 20:
						prizeTypeName = "贡献值";
						break;
					case 30:
						prizeTypeName = "优惠券";
						break;
					case 40:
						prizeTypeName = "谢谢参与";
						break;
				}
				
				return prizeTypeName + "奖励";
			},
			
			
			//奖品名称
			prizeNameFilter(item) {
				
				var prizeNameFormat = "";
				switch(item.prizeType) {
					case 10:
						prizeNameFormat = item.goodName;
						break;
					case 20:
						prizeNameFormat = item.point + "贡献值";
						break;
					case 30:
						prizeNameFormat = item.description;
						break;
				}
				
				return prizeNameFormat;
			},
			
			
			//日期时间格式化
			formatDateTime(dateTime) {
				return dateTimeUtil.formatDateTime(dateTime);
			}
		},
		data() {
			return {
				luckwheelId: "",
				myPrizeList: []
			};
		},
		onLoad(options) {
			this.luckwheelId = options.luckwheelId;
		},
		onShow() {
			
			var that = this;
			that.$api.globalUtil.requestAjax({
				url: "/luckWheelApi/getCustomerReceiveList",
				method: "POST",
				data: {
					luckwheelId: that.luckwheelId
				},
				success: function(res) {
					if(res.data.success) {
						that.myPrizeList = res.data.response;
					}
				},
			});
		},
		methods: {
			
			//去核销
			sureOperateHandler(index) {
				
				let that = this;
				var addFlag = 20;
				var addChannel = 0;//10:PC 20:WAP 30:APP 40：小程序
				
				// #ifdef H5
				addChannel = 20;
				// #endif
				// #ifdef APP-PLUS
				addChannel = 30;
				// #endif
				// #ifdef MP-WEIXIN
				addChannel = 40;
				// #endif
				
				
				var goodsInfo = this.myPrizeList[index];
				
				var goodsId = goodsInfo.goodId;
				var vendorId = goodsInfo.goodVenderId;
				var activityId = goodsInfo.activityId;
				that.$api.globalUtil.requestAjax({
					url: "/ShopCartApi/addShopCartFastBuyForApi",
					method: "POST",
					data: {
						goodsId: goodsId, //商品SKU
						shopId: vendorId, //店铺id
						activityId: activityId, //活动id
						num: 1, //加入数量
						addChannel: addChannel,//加入渠道 10:PC 20:WAP 30:APP 40：小程序
						addFlag: addFlag //加入标识 10:加入购物车 20:立即购买
					},
					success: function(res) {
						if(res.data.success) {
							
							var flag = res.data.response.shopCartSplitForms[0].type == 10 ? 0 : 1;
							uni.setStorageSync('shopCartData', JSON.stringify(res.data.response.shopCartSplitForms));
							
							uni.navigateTo({
								url: '/pagesOrder/createOrder?taxationFlag='+flag+'&prizeReceiveId='+goodsInfo.luckwheelReceiveId
							});
						}
					}
				});
			}
		}
	}
</script>

<style lang="less">
	page {
		background-color: #F5F5F5;
	}
	
	.onePrize {
		display: flex;
		justify-content: space-between;
		margin-top: 20rpx;
		padding: 20rpx 30rpx;
		width:100%;
		height:150rpx;
		background:rgba(255,255,255,1);
		border-radius:16rpx;
		
		.prizeInfo {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			width: 560rpx;
			height: 100%;
			
			.prizeType {
				font-size: 30rpx;
				color: #333333;
			}
			.prizeName, .dateTime {
				max-width: 100%;
				font-size: 22rpx;
				color: #BFBFBF;
			}
		}
		
		.prizeStatus {
			display: flex;
			align-items: center;
			width:114rpx;
			height:100%;
			
			.status {
				width:114rpx;
				height:44rpx;
				line-height: 44rpx;
				text-align: center;
				font-size: 24rpx;
				color: #BFBFBF;
			}
			.goods {
				width:114rpx;
				height:44rpx;
				line-height: 44rpx;
				text-align: center;
				font-size: 24rpx;
				color: #FFFFFF;
				background: #FE5E49;
				border-radius:22rpx;
			}
		}
	}
</style>



